<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>向服务器上传文件</title>
	<script type="text/javascript">
	function uploadFile(){
		var formData = new FormData();
		var files = document.getElementById('file').files;
		console.log(files);
		/*
			FileList {0: File, length: 1, item: function}
				0: File
					lastModifiedDate: Thu Sep 25 2014 19:38:02 GMT+0800 (中国标准时间)
					name: "com-star-sprite-blue.png"
					size: 1620
					type: "image/png"
					webkitRelativePath: ""
					__proto__: File
				length: 1
				__proto__: FileList
		*/
		var file = files[0];

		formData.append('myfile', file);

		var xhr = new XMLHttpRequest();
		xhr.open('post', 'index.html', true);
		xhr.onload = function(e){
			if(this.status == 200){
				document.getElementById('result').innerHTML = this.response;
			}
		};
		xhr.send(formData);
	}

	</script>
</head>
<body>
	<h1>使用bodyParser中间件上传文件</h1>
	<form id="form1" enctype="multipart/form-data">
		请选择文件<input type="file" id="file" name="file"><br/>
		<input type="button" value="上传文件" onclick="uploadFile();">
	</form>
	<output id="result"></output>
</body>

</html>